<template>
  <div class="fareDifferencesInAudit">
    <basic-container>
      <avue-crud
        ref="cashBoxBatchAudit"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :page.sync="page"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="refreshChange"
        @on-load="refreshChange"
        :row-style="rowStyle"
        :cell-style="cellStyle">
        <template slot="menuLeft">
          <el-button
            class="filter-item"
            type="primary"
            :style="{backgroundColor:currPageType==1?'#73ddff':''}"
            size="mini"
            @click="clickCoinsRecycling()">硬币回收箱
          </el-button>
          <el-button
            class="filter-item"
            type="primary"
            :style="{backgroundColor:currPageType==2?'#73ddff':''}"
            size="mini"
            @click="clickCoinsChange()">硬币补充箱
          </el-button>
          <el-button
            class="filter-item"
            type="primary"
	    v-if="false"
            :style="{backgroundColor:currPageType==6?'#73ddff':''}"
            size="mini"
            @click="clickCoinMoney()">硬币钱箱
          </el-button>
          <el-button
            class="filter-item"
            type="primary"
            :style="{backgroundColor:currPageType==3?'#73ddff':''}"
            size="mini"
            @click="clicPaperRecycling()">纸币回收箱
          </el-button>
          <el-button
            class="filter-item"
            type="primary"
            :style="{backgroundColor:currPageType==4?'#73ddff':''}"
            size="mini"
            @click="clickPaperChange()">纸币找零箱
          </el-button>
	   <el-button
            class="filter-item"
            type="primary"
            :style="{backgroundColor:currPageType==5?'#73ddff':''}"
            size="mini"
            @click="clickWasteChange()">废钞箱
          </el-button>
        </template>
        <template
          slot="tvmCode"
          slot-scope="{row}"
        >
       <el-tooltip class="item" effect="dark" content="钱箱清点信息" placement="right-end">
            <el-link
              type="primary"
              @click="previewTVM(row)"
            >{{row.tvmCode}}</el-link>
       </el-tooltip>
      </template>
       <template
          slot="handOutMoney"
          slot-scope="{row}"
        >
          <el-tooltip class="item" effect="dark" content="手工清出信息" placement="right-end">
            <el-link
              type="primary"
              @click="preview(row.handOutMoneyUrl, row)"
            >{{row.handOutMoney | rcaNumberFormat}}</el-link>
          </el-tooltip>
        </template>
        <template slot="menuRight">
          <el-button
            class="filter-item"
            type="primary"
            size="mini"
            v-if="currPageType != 6"
            @click="clickDifferences()">设置差异原因
          </el-button>
          <el-button
            class="filter-item"
            type="primary"
            size="mini"
            @click="clickAudit()">一键审核
          </el-button>
          <el-button type="primary" size="mini"  @click="revoke">撤回审核</el-button>
<!--          <el-button-->
<!--            class="filter-item"-->
<!--            type="primary"-->
<!--            size="mini"-->
<!--            @click="clickJoinTheInvestigation()">加入票款差异协查-->
<!--          </el-button>-->
          <el-button
            class="filter-item"
            type="primary"
            size="mini"
            @click="openClickJoinTheInvestigation()">加入票款差异协查
          </el-button>
          <el-button
            class="filter-item"
            type="primary"
            size="mini"
            v-if="false"
            @click="clickLevelDifference()">加入层级差异协查
          </el-button>
          <el-button
            class="filter-item"
            type="primary"
            size="mini"
            v-if="currPageType != 6"
            @click="submitData()">加入报表差错
          </el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button type="text" size="small" v-if="scope.row.auditStatus==0 && currPageType!=6"  plain @click.stop="editReplace(scope.row)">编辑</el-button>
          <el-button type="text" size="small" v-if="currPageType!=6" plain @click.stop="openPastRecords(scope.row)">查看历史记录</el-button>
          <el-button type="text" size="small" v-if="scope.row.isAddAssist==1" plain @click.stop="previewEditor(scope.row,1)">票款差异</el-button>
          <el-button type="text" size="small" v-if="scope.row.isAddLevelAssist==1" plain @click.stop="previewEditor(scope.row,2)">层级差异协查信息</el-button>
          <el-button type="text" size="small" plain @click.stop="openReplace(scope.row)">数据来源替换</el-button>
        </template>
        <template slot-scope="scope" slot="lineCodeSearch">
          <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" clearable filterable>
            <el-option
              v-for="(item,index) in lineCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="stationCodeSearch">
          <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" clearable @change="changeStation" filterable>
            <el-option
              v-for="(item,index) in stationCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="tvmCodeSearch">
          <el-select v-model="searchForm.tvmCode" placeholder="请选择" style="width: 150px" filterable>
            <el-option
              v-for="(item,index) in tvmCodes"
              :key="index"
              :label="item.tvmCode"
              :value="item.tvmCode">
            </el-option>
          </el-select>
        </template>
        <template slot="search" slot-scope="{row,size}" >
          <el-form-item label="差异条件" style="width: 200px">
            <el-select v-model="searchForm.isDiffMoney" placeholder="请选择"  style="width: 200px" clearable>
              <el-option label="不等于0" value="0"></el-option>
              <el-option label="等于0" value="1"></el-option>
              <!-- <el-option label="大于0" value="2"></el-option> -->
            </el-select>
          </el-form-item>
        </template>
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);
            setSearchFiledsEmpty(searchForm);
            //getList()
            }" icon="el-icon-delete">清空</el-button>
        </template>
      </avue-crud>
    </basic-container>
    <el-dialog
      title="设置差异原因"
      :visible.sync="dialogVisible"
      width="30%" >
      <!-- <el-select type="select" :rows="5" placeholder="请选择原因" v-model="diffReason">
        <el-option label="平账" value="1"></el-option>
        <el-option label="补币或清点错误" value="2"></el-option>
        <el-option label="系统原因" value="3"></el-option>
        <el-option label="待确认" value="4"></el-option>
      </el-select> -->
      <el-form label-width="60px" v-if="dialogVisible">
        <avue-form
          v-model="formChaYi"
          :option="tableOptionChaYi"
        ></avue-form>
      </el-form>
      <template>
        <div class="bottom-diffReason">
        <el-button
          type="primary"
          @click="submitDifferences()">确定
        </el-button>
        <el-button
          type="primary"
          @click="dialogVisible = false">取消
        </el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog
      title="加入票款差异协查"
      :visible.sync="clickJoinTheInvestigationView"
      @close="closeClickJoinTheInvestigationView"
      width="950px">
      <el-form :model="clickJoinTheInvestigationData">
        <el-form-item label="车站备注" prop="remark">
          <el-input type="textarea"
                    placeholder="请输入车站备注"
                    class="custom-textarea"
                    v-model="clickJoinTheInvestigationData.remark"></el-input>
        </el-form-item>
      </el-form>
      <div class="bottom-menu-hand">
        <el-button type="primary" @click="clickJoinTheInvestigation"
        >保存</el-button
        >
        <el-button type="primary" @click="closeClickJoinTheInvestigationView"
        >返回</el-button
        >
      </div>
    </el-dialog>

    <open-dialog
        :DialogVisible.sync="editReplaceVisableDialog"
        title="编辑"
        width="60%"
        :before-close="closeDialog"
      >
      <el-form label-width="60px" v-if="editReplaceVisableDialog">
        <avue-form
          v-model="formEdit"
          :option="tableOptionEditTvm"
          style="margin-bottom: 40px"
        ></avue-form>
        <div class="bottom-menu-revenue">
          <el-button type="primary" @click="edit">保存</el-button>
          <el-button type="primary" @click="closeDialog"
            >取消</el-button
          >
        </div>
      </el-form>
    </open-dialog>
    <open-dialog
          :DialogVisible.sync="handCleanVisableDialog"
          title="手工清出详情"
          width="60%"
        :before-close="closehandCleanDialog"
        >
        <avue-crud :data="handCleanData" :option="tableOptionView" title="手工清出明细"></avue-crud>
        <div class="bottom-menu-hand">
          <el-button type="primary" @click="closehandCleanDialog"
            >返回</el-button
          >
        </div>
      </open-dialog>
      <open-dialog
          :DialogVisible.sync="tvmCheckVisableDialog"
          title="TVM钱箱清点详情"
          width="60%"
        :before-close="closetvmCheckDialog"
        >
        <el-form v-if="tvmCheckVisableDialog">
          <avue-form
            v-model="formtvmCheck"
            :option="tvmCheckOptionView"
            style="margin-top:38px"
          ></avue-form>
        </el-form>
        <el-tabs v-model="active" v-if="tvmCheckVisableDialog" style="margin-top: -40px;">
          <el-tab-pane label="硬币回收箱" name="1" v-if="currPageType==1||currPageType==6" style="margin-top: -40px;">
            <dynamic-crud
              :data="coinData"
              :option="tvmCheckOptionDetailView"
            ></dynamic-crud>
          </el-tab-pane>
          <el-tab-pane label="硬币补充箱" name="2" v-if="currPageType==2||currPageType==6" style="margin-top: -40px;">
            <dynamic-crud
              :data="coinChangeData"
              :option="tvmCheckOptionDetailView"
            ></dynamic-crud>
          </el-tab-pane>
          <el-tab-pane label="纸币回收箱" name="3" v-if="currPageType==3" style="margin-top: -40px;">
            <dynamic-crud
              :data="paperData"
              :option="tvmCheckOptionDetailView"
            ></dynamic-crud>
          </el-tab-pane>
          <el-tab-pane label="纸币找零箱" name="4" v-if="currPageType==4" style="margin-top: -40px;">
            <dynamic-crud
              :data="paperChangeData"
              :option="tvmCheckOptionDetailView"
            ></dynamic-crud>
          </el-tab-pane>
          <el-tab-pane label="废钞箱" name="5" v-if="currPageType==5" style="margin-top: -40px;">
            <dynamic-crud
              :data="wasteData"
              :option="tvmCheckOptionDetailView"
            ></dynamic-crud>
          </el-tab-pane>
        </el-tabs>
        <div class="bottom-menu-tvm">
          <el-button type="primary" @click="closetvmCheckDialog"
            >返回</el-button
          >
        </div>
      </open-dialog>
      <open-dialog
        :DialogVisible.sync="visableDialogRecordsSC"
        title="查看历史记录"
        width="60%"
      >
        <avue-crud
          :data="tableData"
          :option="tableOptionEditRecordsSC">
        </avue-crud>
        <div class="bottom-menu-close">
          <el-button type="primary" @click="visableDialogRecordsSC=false"
            >取消</el-button
          >
        </div>
      </open-dialog>
    <replace ref="replace" v-if="isShowReplace" :home='this'></replace>
    <addReportEditor ref="addReportEditor" @addReportSuccess="getList"></addReportEditor>
    <HuikuiInfo ref="HuikuiInfo" v-if="isShowDia"></HuikuiInfo>
  </div>
</template>
<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {mapGetters} from 'vuex';
  import replace from './replace';
  import {tableOption,getDifferencesInAudit,updateAuditStatus,
    insertSwAuTvmMoneyAssist,insertSwAuTvmCashboxAmountHierarchyDifference,tableOptionChaYi
  } from '../../../../api/subwayRat/TVMRevenueVarianceAudit/cashBoxBatchAudit/index';
  import {
    tvmCheckOptionView,
    tvmCheckOptionDetailView,
    queryTVM,
    getTvmObj, 
    fetchList,
    tableOptionView
  } from '@/api/subwayRat/TVMRevenueVarianceAudit/differencesInAudit/fareDifferencesInAudit';
  import {
    tableOptionEditTvm,tableOptionEditRecordsSC,tableOptionEditRecordsFQX,tableOptionEditRecordsJZDJ,
    update,queryPastRecords,revoke
  } from '@/api/subwayRat/TVMRevenueVarianceAudit/cashBoxBatchAudit/index';
  import transitUtil from "../../../../api/subwayRat/transitUtil";
  import {getTvmTicketCYXCList} from "../../../../api/subwayRat/TVMRevenueVarianceAudit.TvmChaYiDXC/TvmTicketCYXC";
  import {getSwAuTvmCashboxAmountHierarchyDifferenceList} from "../../../../api/subwayRat/TVMRevenueVarianceAudit.TvmChaYiDXC/tvmCengJiCYXC/tvmXianJinCengJiCYDXY/fenQianXiangCengJiCYDXC";
  import {
    fenExYuangettoFixed2,
    getgetStationCodes,
    getLineCodes,
    getSwPmTvmCodeList,
    setSearchFiledsEmpty
  } from "../../../../api/subwayRat/commonCheck";
  import {getListCionMOney,updateDifferences} from "../../../../api/subwayRat/TVMRevenueVarianceAudit/cashBoxBatchAudit";
  import addReportEditor from '@/views/subwayRat/reportMondify/reportMistakeInfo/Editor';
  import { fenExYuangettoFixed } from "../../../../api/subwayRat/commonCheck";
  import row from "element-ui/packages/row";
  import moment from "moment/moment";
  import HuikuiInfo from "@/views/subwayRat/TVMRevenueVarianceAudit/TvmChaYiDXC/TvmTicketCYXC/HuikuiInfo.vue";
  import { rcaNumberFormat } from '@/api/subwayRat/TVMRevenueVarianceAudit/differencesInAudit/common';
  export default {
    components:{
      HuikuiInfo,
      replace,addReportEditor
    },
    name: 'index',
    filters: {
      rcaNumberFormat (val) {
        return rcaNumberFormat(val, true)
      }
    },
    data() {
      return {
        isShowDia:false,
        tvmCodes:[],
        lineCodes:[],
        stationCodes:[],
        option: tableOption,
        listLoading: true,
        dialogVisible:false,
        diffReason:'',
        isShowReplace:false,//是否展示替换页面
        searchForm:{
          lineCode:'9',
          stationCode:'',
          tvmCode:'',
          isDiffMoney:'0',
          auditStatus:'0',
          cashBoxType:'1',
        },
        currPageType:'1',//当前页面类型
        dialogVisibleLevelReplace:{ //数据来源替换
          dialogVisible:false,
          dataSource:'',
          levels: [{label:'修正',"value":1}, {label:'SC',"value":2},
            {label:'LC',"value":3}, {label:'ACC',"value":4},{label:'单台设备差异协查结果',value:5},{label:'分钱箱票款差异协查',value:6}],
          row:{}
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          current: 1,// 当前页数
          pageSize: 20, // 每页显示多少条,
          size: 20,// 每页显示多少条
          isAsc: false// 是否倒序
        },
        clickJoinTheInvestigationView: false,
        clickJoinTheInvestigationData:{
          remark: ''
        },
        list : [],
        checkList : [],
        formEdit: {},
        tableOptionEditTvm:tableOptionEditTvm,
        tableOptionEditRecordsSC:tableOptionEditRecordsSC,
        tableOptionChaYi: tableOptionChaYi,
        formChaYi:{},
        editReplaceVisableDialog:false,
        visableDialogRecordsSC:false,
        tableData: [],
        formtvmCheck: {},
        tvmCheckVisableDialog: false,
        tvmCheckOptionView: tvmCheckOptionView,
        tvmCheckOptionDetailView: tvmCheckOptionDetailView,
        tvmTableData: [],
        active: "1",
        coinData: [],
        coinChangeData: [],
        paperData: [],
        paperChangeData: [],
        wasteData: [],
        replaceRow: {},
	handCleanVisableDialog: false, //手工清出相关参数
	handCleanData: [],
	tableOptionView: tableOptionView
      }
    },
    computed: {
    },
    watch: {
      formEdit: {
        handler() {
          //人工修改
          if(this.formEdit.dataSource == '1'){
              //差异金额=卸载实点金额+手工清出金额-系统金额   自动计算
              this.formEdit.diffMoney = this.formEdit.actualMoney + this.formEdit.handOutMoney - this.formEdit.billOrderMoney;
          }
          //SC
          if(this.formEdit.dataSource == '2'){
              //差异金额=卸载实点金额+手工清出金额-系统金额   自动计算
              this.formEdit.diffMoney = this.formEdit.actualMoney + this.formEdit.handOutMoney - this.formEdit.scUnloadAmount;
          }
          //分钱箱审核结果
          if(this.formEdit.dataSource == '6'){
              //差异金额=卸载实点金额+手工清出金额-系统金额   自动计算
              this.formEdit.diffMoney = this.formEdit.actualMoney + this.formEdit.handOutMoney - this.formEdit.replyUnloadDisplayMoney;
	      //this.formEdit.replyActualMoney;
          }
        },
        immediate: true,
        deep: true
      },
    },
    created() {
      this.changeLine("9")
      if(this.$route.query.fareDifferencesInAuditParam != "" && this.$route.query.fareDifferencesInAuditParam != undefined){
        this.searchForm=JSON.parse(this.$route.query.fareDifferencesInAuditParam);
        if(this.searchForm.stationCode != "") {
          getgetStationCodes(this.searchForm.lineCode).then(res => {
            this.stationCodes = res;
          })
        }
      }
      this.getList();
    },
    methods: {
      setSearchFiledsEmpty,
      refreshChange(){
        this.getList()
      },
      changeStation(v){ //改变车站
        let param={};
        param.lineCode=this.searchForm.lineCode;
        param.stationCode=v;
        getSwPmTvmCodeList(param).then(r=>{
          this.tvmCodes=r.data;
        });
      },
      changeLine(v){ //改变线路时
        getgetStationCodes(v).then(res=>{
          this.stationCodes=res;
          this.searchForm.stationCode='';
        })
      },
      async previewTVM (row) {
        let params = {
          lineCode:row.lineCode,
          stationCode:row.stationCode,
          revenueTime:row.recordTime.substr(0, 10),
          tvmCode:row.tvmCode
        };
        await queryTVM(params).then((response) => {
          this.formtvmCheck = response.data.data[0];
        });
        if(this.formtvmCheck!=null || this.formtvmCheck!=undefined){
          if(this.currPageType==1){
            this.active = "1";
          }else if(this.currPageType==2){
            this.active = "2";
          }else if(this.currPageType==3){
            this.active = "3";
          }else if(this.currPageType==4){
            this.active = "4";
          }else if(this.currPageType==5){
            this.active = "5";
          }else if(this.currPageType==6){
            this.active = "1";
          }
          this.tvmCheckVisableDialog = true;
          getTvmObj(this.formtvmCheck.id,1).then((res) => {
            this.coinData = res.data.data.swStTvmCheckDetailCoins;
            this.coinChangeData = res.data.data.swStTvmCheckDetailCoinChanges;
            this.paperData = res.data.data.swStTvmCheckDetailPapers;
            this.paperChangeData = res.data.data.swStTvmCheckDetailPaperChanges;
            this.wasteData = res.data.data.swStTvmCheckDetailWastes;
          });
        }else{
          this.$message.info("没有获取到钱箱清点信息！");
        }
      },
      async preview (target, row) {
        let params = {
          lineCode:row.lineCode,
          stationCode:row.stationCode,
          tvmCode: row.tvmCode,
          incomeSettleBeginTime: row.incomeSettleBeginTime,
          incomeSettleEndTime: row.incomeSettleEndTime
        };
        await fetchList(params).then((response) => {
          this.handCleanData = response.data.data;
          this.handCleanVisableDialog = true;
        });
        if(this.handCleanData!=null || this.handCleanData!=undefined){
          
        }else{
          this.$message.info("没有获取到手工清出信息！");
        }
      },
      closetvmCheckDialog(){
        this.coinData = [],
        this.coinChangeData = [],
        this.paperData = [],
        this.paperChangeData = [],
        this.wasteData = [],
        this.tvmCheckVisableDialog = false;
      },
      cellStyle({ row, column, rowIndex,columnIndex }) {
        if(10==columnIndex){
          if (row.diffMoney < 0) {
            return {
              color: "red",
            };
          }else if (row.diffMoney > 0) {
            return {
              color: "green",
            };
          }
        }
      },
      //颜色特殊标识
      rowStyle({ row, column, rowIndex }) {
        if (row.isModify == 0) {
          return {
            backgroundColor: "#eee",
            color: "red",
          };
        }
      },

      openReplace(row){
        this.replaceRow = row;
        this.isShowReplace=true;
        this.$nextTick(()=>{
          this.$refs.replace.dialogVisible=true;
          this.$refs.replace.getLists(row);
        })
      },
      closeClickJoinTheInvestigationView(){
        this.clickJoinTheInvestigationData = {remark: ''};
        this.clickJoinTheInvestigationView = false;
      },
      openClickJoinTheInvestigation(){
        if(this.checkList == 0){
          this.$message({message: '请勾选数据',type: 'warning'});
          return;
        }
        if(this.checkList.length > 1){
          this.$message({message: '只能勾选一条数据',type: 'warning'});
          return;
        }
        for (let i = 0; i < this.checkList.length; i++) {
          if (this.checkList[i].auditStatus == 1) {
            this.$message.warning("请选择未审核的数据！");
            return;
          }
        }
        let params = {
          lineCode:this.checkList[0].lineCode,
          stationCode:this.checkList[0].stationCode,
          tvmCode: this.checkList[0].tvmCode,
          incomeSettleBeginTime: this.checkList[0].incomeSettleBeginTime,
          incomeSettleEndTime: this.checkList[0].incomeSettleEndTime
        };
        fetchList(params).then((response) => {
          let remark = ''
          for (let i = 0; i < response.data.data.length; i++) {
            if (response.data.data[i].remark != '' && response.data.data[i].remark != null) {
              let formattedCleanTime = moment(response.data.data[i].cleanTime).format('YYYY-MM-DD');
              remark = remark + formattedCleanTime + " " + response.data.data[i].remark + "\n"
            }
          }
          this.clickJoinTheInvestigationData.remark = remark;
          this.clickJoinTheInvestigationData.id = this.checkList[0].id;
          this.clickJoinTheInvestigationView = true;
        });
      },
      clickJoinTheInvestigation(){
        // if(this.checkList == 0){
        //   this.$message({message: '请勾选数据',type: 'warning'});
        //   return;
        // }
        // for (let i = 0; i < this.checkList.length; i++) {
        //   if (this.checkList[i].auditStatus == 1) {
        //     this.$message.warning("请选择未审核的数据！");
        //     return;
        //   }
        // }
        var ids=[];
        this.checkList.forEach(function (key, val) {
          ids[val] = key.id
        })
        let p = {
          ids : JSON.stringify(ids),
          remark : this.clickJoinTheInvestigationData.remark
        };
        insertSwAuTvmMoneyAssist(p).then((response)=>{
          if(response.data.code == "1"){
            this.$message({
              message: '加入成功',
              type: 'success'
            });
            this.closeClickJoinTheInvestigationView()
            this.getList();
          }
        });
      },
      clickLevelDifference(){
        if(this.checkList == 0){
          this.$message({message: '请勾选数据',type: 'warning'});
          return;
        }
        var ids=[];
        this.checkList.forEach(function (key, val) {
          ids[val] = key.id
        })
        let p = {
          ids : JSON.stringify(ids)
        };
        insertSwAuTvmCashboxAmountHierarchyDifference(p).then((response)=>{
          if(response.data.code == "1"){
            this.$message({
              message: '加入成功',
              type: 'success'
            });
            this.getList();
          }
        });
      },
      async clickAudit(){
        if(this.checkList == 0){
          this.$message({message: '请勾选数据后审批',type: 'warning'});
          return;
        }
        var ids=[];
        for(let i=0;i<this.checkList.length;i++){
          if(this.checkList[i].isModify == 0){
            // this.$message.warning("勾选数据中存在报表差错未完成的数据！");
            // return;
          } else {
            ids.push(this.checkList[i].id)
          }
        }
        let res = await this.$confirm('是否一键审核？', '提示', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning'
        });
        if (!res) {
          return;
        }
        // this.checkList.forEach(function (key, val) {
        //   ids[val] = key.id
        // })
        let p = {
          ids : JSON.stringify(ids)
        };
        let response = await updateAuditStatus(p);
          if(response.data.code == "1"){
            this.$message({
              message: '审核完成',
              type: 'success'
            });
            this.getList();
          }
      },
      clickCoinsRecycling(){
          this.searchForm.cashBoxType = 1;
          this.currPageType=1;
          this.getList();
      },
      clickCoinsChange(){
        this.searchForm.cashBoxType = 2;
        this.currPageType=2;
        this.getList();
        },
      clicPaperRecycling(){
        this.searchForm.cashBoxType = 3;
        this.currPageType=3;
        this.getList();
      },
      clickPaperChange(){
        this.searchForm.cashBoxType = 4;
        this.currPageType=4;
        this.getList();
      },
      clickWasteChange(){
        this.searchForm.cashBoxType = 5;
        this.currPageType=5;
        this.getList();
      },
      clickCoinMoney(){//点击硬币钱箱
        this.searchForm.cashBoxType = 6;
        this.currPageType=6;
        this.getListCionMOney();
      },
      async submitDifferences(){
        this.dialogVisible = false;
        if('' != this.formChaYi.diffReason){
          var ids=[];
          this.checkList.forEach(function (key, val) {
            ids[val] = key.id
          })
          let p = {
            diffReason : this.formChaYi.diffReason,
            ids : JSON.stringify(ids)
          };
          let response = await updateDifferences(p);
          if(response.data.code == "0"){
            this.$message({
              message: '设置成功',
              type: 'success'
            });
            this.getList();
          }else{
            this.$message({
              message: '设置失败',
              type: 'warning'
            });
          }
        }
      },
      clickDifferences(){
        if(this.checkList == 0){
          this.$message({message: '请勾选数据',type: 'warning'});
          return;
        }
        this.dialogVisible = true;
        this.formChaYi = {};
      },
      getList() {
        if(this.currPageType==6){ //如果为硬币钱箱，则查询视图数据
          this.getListCionMOney();
          return;
        }
        const params = this.$route.query;
        const p = {};
        if (Object.keys(params).length) {
          if (params.pathType == "1") {
            p.lineCode = params.lineCode;
            p.stationCode = params.stationCode;
            p.tvmCode = params.tvmCode;
            p.recordTime = params.reprotTime;
            p.cashBoxType = params.cashboxType;
          }
        }
        this.listLoading = true;
        this.page.size = this.page.pageSize;
        this.page.current = this.page.currentPage;
        this.searchForm.userCode = this.$store.getters.userInfo.userCode;
        // Object.assign(this.searchForm,this.$refs.cashBoxBatchAudit?this.$refs.cashBoxBatchAudit.searchForm:{});
        Object.assign(this.searchForm,this.page);
        console.log("this.searchForm"+JSON.stringify(this.searchForm))
        console.log("p"+JSON.stringify(p))
        getDifferencesInAudit(Object.keys(p).length ? p : this.searchForm).then((response)=>{
          this.list = response.data.data.records;
          this.page.total=response.data.data.total;
          this.listLoading = false;
        });
      },
      getListCionMOney() { //获取硬币钱箱列表
        this.listLoading = true;
        this.page.size = this.page.pageSize;
        this.page.current = this.page.currentPage;
        this.searchForm.userCode = this.$store.getters.userInfo.userCode;
        // Object.assign(this.searchForm,this.$refs.cashBoxBatchAudit?this.$refs.cashBoxBatchAudit.searchForm:{});
        Object.assign(this.searchForm,this.page);
        getListCionMOney(this.searchForm).then((response)=>{
          this.list = response.data.data.records;
          this.page.total=response.data.data.total;
          this.listLoading = false;
        });
      },
      selectionChange(list){
        this.checkList = list;
      },
      handleFilter(params, done) {
        Object.assign(this.searchForm,params);
        this.getList();
        done();
      },
      dataSourceReplace(row){
        this.dialogVisibleLevelReplace.dialogVisible=true;
        this.dialogVisibleLevelReplace.row=row;
      },
      previewEditorPK(row){ //回馈预览
        this.isShowDia=true;
        this.$nextTick(()=>{
          this.$refs.HuikuiInfo.recallShow(row.id,row,3);
        })
      },
      previewEditor(row,type){ //查看回馈信息 assistInvestStatus
        let feedbackPath="";
        let feedbackEventStr="";
        if(1 == type){//票款
          let th=this;
          // feedbackPath="/subwayRat/TVMRevenueVarianceAudit/TvmChaYiDXC/TvmTicketCYXC/TvmTicketCYXC";
          getTvmTicketCYXCList({relationid:row.id}).then((response)=>{
            th.data = response.data.data;
            th.previewEditorPK(th.data[0]);
            // if(response.data && response.data.data[0] && response.data.data[0].replyStatus == 1){//票款 已回馈
            //   feedbackEventStr = "PK_call";
            // }else if(response.data && response.data.data[0] && response.data.data[0].assistInvestStatus == 1){//票款 待下发
            //   feedbackEventStr = "PK_view";
            // }else if(response.data && response.data.data[0] && response.data.data[0].assistInvestStatus == 2 && response.data.data[0].replyStatus == 0){//已下发 未回馈
            //   this.$message({message: '已下发，等待回馈',type: 'warning'});
            //   return;
            // }
            // this.$router.push({path:feedbackPath,query:row});
            // setTimeout(function () {
            //   transitUtil.$emit(feedbackEventStr,row);
            // },1000)
          });
        }else if(2 == type){
          feedbackPath="/subwayRat/TVMRevenueVarianceAudit/TvmChaYiDXC/tvmCengJiCYXC/tvmXianJinCengJiCYDXY/fenQianXiangCengjiCYDXC/fenQianXiangCengjiCYDXC";
          getSwAuTvmCashboxAmountHierarchyDifferenceList({relationSourceboxId:row.id}).then((response)=>{
            if(response.data && response.data.data[0] && response.data.data[0].assistStatus==3){//票款 已回馈
              feedbackEventStr = "FQX_SC_call";
            }else if(response.data && response.data.data[0] && response.data.data[0].assistStatus == 1){//票款 待下发
              feedbackEventStr = "FQX_SC_view";
            }else if(response.data && response.data.data[0] && response.data.data[0].assistStatus == 2){//已下发 未回馈
              this.$message({message: '已下发，等待回馈',type: 'warning'});
              return;
            }
            this.$router.push({path:feedbackPath,query:row});
            setTimeout(function () {
              transitUtil.$emit(feedbackEventStr,row);
            },1000)
          });
        }
        return;
      },
      async submitData() {
        if (this.checkList.length != 1) {
          this.$message.warning("请选择一条要加入的数据！");
          return;
        }
        for (let i = 0; i < this.checkList.length; i++) {
          if (this.checkList[i].auditStatus == 1) {
            this.$message.warning("请选择未审核的数据！");
            return;
          }
        }
        let res = await this.$confirm('是否提交报表差错？', '提示', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning'
        });
        if (!res) {
          return;
        }
        // this.checkList[0].reportNameId = '4';
        // this.$router.push({ path: '/subwayRat/reportMondify/reportMistakeInfo',query:{row:this.checkList[0]}})

        let param = {
          resultIds:this.checkList[0].id,
          operatorTable:"sw_au_tvm_box_amount_difference",
          lineCode: this.checkList[0].lineCode,
          stationCode: this.checkList[0].stationCode,
          tvmCode: this.checkList[0].tvmCode,
          reprotTime: this.checkList[0].recordTime,
	  settleBeginTime:this.checkList[0].incomeSettleBeginTime,
          settleEndTime:this.checkList[0].incomeSettleEndTime,
          reportNameId: 5,
          //cashboxCode: this.checkList[0].cashBoxCode,
          cashboxType: this.checkList[0].cashBoxType,
          userCodes: this.checkList[0].attendancePersonJobNo,//(this.checkList[0].updateJobNo)?this.checkList[0].updateJobNo:this.checkList[0].passengerJobNo,
	  dutyStationLeaderCode:this.checkList[0].passengerJobNo,
	  dutyStationLeaderName:this.checkList[0].passengerJobName,
          showType: 3,
          dataSource: 5,
          errorAmount:fenExYuangettoFixed2(this.checkList[0].diffMoney)
        };
        this.$refs.addReportEditor.others_report_add_call(param);
      },
      formatterAmount(row,isYuan){ //格式化钱
        if(isYuan){
          row.billOrderMoney=fenExYuangettoFixed(row,'billOrderMoney');
          row.scUnloadAmount=fenExYuangettoFixed(row,'scUnloadAmount');
          row.replyActualMoney=fenExYuangettoFixed(row,'replyActualMoney');
          row.replyUnloadDisplayMoney=fenExYuangettoFixed(row,'replyUnloadDisplayMoney');
          row.actualMoney=fenExYuangettoFixed(row,'actualMoney');
          row.supplementMoney=fenExYuangettoFixed(row,'supplementMoney');
          row.handOutMoney=fenExYuangettoFixed(row,'handOutMoney');
          row.diffMoney=fenExYuangettoFixed(row,'diffMoney');
        }else if(!isYuan){
          row.billOrderMoney=Number(row.billOrderMoney)*100;
          row.scUnloadAmount=Number(row.scUnloadAmount)*100;
          row.replyActualMoney=Number(row.replyActualMoney)*100;
          row.replyUnloadDisplayMoney=Number(row.replyUnloadDisplayMoney)*100;
          row.actualMoney=Number(row.actualMoney)*100;
          row.supplementMoney=Number(row.supplementMoney)*100;
          row.handOutMoney=Number(row.handOutMoney)*100;
          row.diffMoney=Number(row.diffMoney)*100;
        }
        return row;
      },
      editReplace(row){
        if(row.dataSource==1){
          this.tableOptionEditTvm.column[1].display = true;
          this.tableOptionEditTvm.column[2].display = true;
          this.tableOptionEditTvm.column[3].display = true;
          this.tableOptionEditTvm.column[4].display = true;
          this.tableOptionEditTvm.column[5].display = true;

	  this.tableOptionEditTvm.column[6].display = false;
          this.tableOptionEditTvm.column[7].display = false;
          this.tableOptionEditTvm.column[8].display = false;
          this.tableOptionEditTvm.column[9].display = false;
          this.tableOptionEditTvm.column[10].display = false;
	  this.tableOptionEditTvm.column[11].display = false;
	  this.tableOptionEditTvm.column[12].display = false;
          this.tableOptionEditTvm.column[13].display = false;
          this.tableOptionEditTvm.column[14].display = false;
          this.tableOptionEditTvm.column[15].display = false;

          this.editReplaceVisableDialog = true;
        }else if(row.dataSource==2){
          this.tableOptionEditTvm.column[6].display = true;
          this.tableOptionEditTvm.column[7].display = true;
          this.tableOptionEditTvm.column[8].display = true;
          this.tableOptionEditTvm.column[9].display = true;
          this.tableOptionEditTvm.column[10].display = true;

	  this.tableOptionEditTvm.column[1].display = false;
          this.tableOptionEditTvm.column[2].display = false;
          this.tableOptionEditTvm.column[3].display = false;
          this.tableOptionEditTvm.column[4].display = false;
          this.tableOptionEditTvm.column[5].display = false;
	  this.tableOptionEditTvm.column[11].display = false;
	  this.tableOptionEditTvm.column[12].display = false;
          this.tableOptionEditTvm.column[13].display = false;
          this.tableOptionEditTvm.column[14].display = false;
          this.tableOptionEditTvm.column[15].display = false;
          this.editReplaceVisableDialog = true;
        }else if(row.dataSource==6){

          this.tableOptionEditTvm.column[11].display = true;
	  this.tableOptionEditTvm.column[12].display = true;
          this.tableOptionEditTvm.column[13].display = true;
          this.tableOptionEditTvm.column[14].display = true;
          this.tableOptionEditTvm.column[15].display = true;

	  this.tableOptionEditTvm.column[1].display = false;
          this.tableOptionEditTvm.column[2].display = false;
          this.tableOptionEditTvm.column[3].display = false;
          this.tableOptionEditTvm.column[4].display = false;
          this.tableOptionEditTvm.column[5].display = false;

	  this.tableOptionEditTvm.column[6].display = false;
          this.tableOptionEditTvm.column[7].display = false;
          this.tableOptionEditTvm.column[8].display = false;
          this.tableOptionEditTvm.column[9].display = false;
          this.tableOptionEditTvm.column[10].display = false;
          this.editReplaceVisableDialog = true;
        }
        //this.formEdit = row;
        this.formEdit.id = row.id;
        this.formEdit.dataSource = row.dataSource;
        this.formEdit.lineCode = row.lineCode;
        this.formEdit.stationCode = row.stationCode;
        this.formEdit.tvmCode = row.tvmCode;
        this.formEdit.cashBoxType = row.cashBoxType;
        this.formEdit.incomeSettleBeginTime = row.incomeSettleBeginTime;
        this.formEdit.incomeSettleEndTime = row.incomeSettleEndTime;
        this.formEdit.billOrderMoney = row.billOrderMoney;
        this.formEdit.scUnloadAmount = row.scUnloadAmount;
        this.formEdit.replyActualMoney = row.replyActualMoney;
        this.formEdit.replyUnloadDisplayMoney = row.replyUnloadDisplayMoney;
        this.formEdit.actualMoney = row.actualMoney;
        this.formEdit.supplementMoney = row.supplementMoney;
        this.formEdit.handOutMoney = row.handOutMoney;
        this.formEdit.diffMoney = row.diffMoney;
        this.formEdit.reasonRemark = row.reasonRemark;
        this.$nextTick(() => {
          this.formatterAmount(this.formEdit,true);
        })
      },
      edit(){
        if(this.formEdit.reasonRemark == '' || this.formEdit.reasonRemark == undefined || this.formEdit.reasonRemark == null){
          this.$message.error('修改原因备注不能为空！');
            return
        }
        this.formatterAmount(this.formEdit,false);
        update(this.formEdit).then(data => {
            this.$message.success('编辑成功！');
            this.closeDialog();
            this.getList();
          }).catch(() => {

          });
      },
      async queryPastRecords(row){
        let param={};
        param.id=row.id;
        param.cashBoxType=row.cashBoxType;//钱箱类型根据当前数据获取
        param.dataSource=row.dataSource;
        await queryPastRecords(param)
          .then(response => {
            this.tableData = response.data.data;
          })
      },
      openPastRecords(row){
        this.queryPastRecords(row);
        this.visableDialogRecordsSC=true;
      },
      closeDialog(){
        this.editReplaceVisableDialog = false;
        for(var i=1;i<=11;i++){
          this.tableOptionEditTvm.column[i].display = false;
        }
      },
      closehandCleanDialog(){
        this.handCleanData =[];
        this.handCleanVisableDialog = false;
      },
      //审核通过的才能撤回
      revoke: function () {
        if (this.checkList.length === 0) {
          this.$message.error('请选择要撤回的数据！');
          return;
        }
        for(let i =0;i<this.checkList.length;i++){
          if(this.checkList[i].auditStatus==0){
            this.$message.warning("只能撤回审批通过的数据！");
            return;
          }
        }
        var ids=[];
        this.checkList.forEach(function (key, val) {
          ids[val] = key.id
        })
        this.$confirm("是否需要撤回?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "success"
        }).then(() => {
          revoke({ids: ids})
            .then(data => {
              if (data.data.code == "0") {
                this.$message.success("撤回成功！");
              }
              this.getList(this.page);
              done();
            })
            .catch(() => {
              loading();
            });
        });
      },
    },
    mounted() {
      getLineCodes().then(res=>{ //获取线路
        this.lineCodes=res;
      });
    }
  }
</script>
<style lang="scss">
  .bottom-diffReason {
    margin-top: 25px;
    text-align: center;
  }
  .bottom-menu-revenue {
    text-align: center;
  }
  .bottom-menu-close{
    text-align: center;
    margin-top: 50px;
  }
  .bottom-menu-tvm{
    text-align: center;
    margin-top: 10px;
  }
  .bottom-menu-hand{
    text-align: center;
    margin-top: 50px;
  }
  .custom-textarea .el-textarea__inner {
    height: 100px; /* 设置你想要的高度 */
  }
</style>
